** Organize CPS data in a format that is ready for grandparent-level analysis.
*******************************************************************************

use CPS/OldGenParentData


** Merge in info about EITC eligibility for middle generation living in same household
** (File naming is bad here.  MaxMidGenEITC also includes several other variables about 
** the characteristics of the middle generation)
merge m:1 serial year month using CPS/MaxMidGenEITC
drop if _merge==2
drop _merge
merge m:1 serial year month using CPS/SumMidGenEITC
drop if _merge==2
drop _merge


** Impose a (sensible but arbitrary) minimum age restriction
drop if age<30


** Create other helpful variables
gen ExcellentVeryGoodHealth = (health==1 | health==2)
replace ExcellentVeryGoodHealth = . if health==.
gen PoorHealth = (health==5)
replace PoorHealth = . if health==.

gen AgeSq = age*age

** Merge in state controls
gen tfipsst = statefip
gen rhcalyr = year
merge m:1 tfipsst rhcalyr using OrganizedStateControls

drop if _merge==2


gen real = 1
replace real = 229.594/255.657 if rhcalyr==2019
replace real = 229.594/251.107 if rhcalyr==2018
replace real = 229.594/245.120 if rhcalyr==2017
replace real = 229.594/240.007 if rhcalyr==2016
replace real = 229.594/237.017 if rhcalyr==2015
replace real = 229.594/236.736 if rhcalyr==2014
replace real = 229.594/232.957 if rhcalyr==2013
replace real = 229.594/229.594 if rhcalyr==2012
replace real = 229.594/224.939 if rhcalyr==2011
replace real = 229.594/218.056 if rhcalyr==2010
replace real = 229.594/214.537 if rhcalyr==2009
replace real = 229.594/215.303 if rhcalyr==2008
replace real = 229.594/207.342 if rhcalyr==2007
replace real = 229.594/201.6 if rhcalyr==2006
replace real = 229.594/195.3 if rhcalyr==2005
replace real = 229.594/188.9 if rhcalyr==2004
replace real = 229.594/184 if rhcalyr==2003
replace real = 229.594/179.9 if rhcalyr==2002
replace real = 229.594/177.1 if rhcalyr==2001
replace real = 229.594/172.2 if rhcalyr==2000
replace real = 229.594/166.6 if rhcalyr==1999
replace real = 229.594/163 if rhcalyr==1998
replace real = 229.594/160.5 if rhcalyr==1997
replace real = 229.594/156.9 if rhcalyr==1996
replace real = 229.594/152.4 if rhcalyr==1995
replace real = 229.594/148.2 if rhcalyr==1994
replace real = 229.594/144.5 if rhcalyr==1993
replace real = 229.594/140.3 if rhcalyr==1992
replace real = 229.594/136.2 if rhcalyr==1991
replace real = 229.594/130.7 if rhcalyr==1990


gen r_MaxWelf = MaxWelf*real

gen EITC_v3 = Sum_MaxEITC_MidGenMoms
replace EITC_v3 = r_MaxEITC_MidGenMax if EITC_v3==.

gen ref_EITC_v3 = Sum_ref_MaxEITC_MidGenMoms
replace ref_EITC_v3 = r_ref_MaxEITC_MidGenMax if ref_EITC_v3==.

gen EITC_FedOnly_v3 = Sum_MaxFedEITC_MidGenMoms
replace EITC_FedOnly_v3 = r_MaxFedEITC_MidGenMax if EITC_FedOnly_v3==.

** Version based on simulated EITC measure.  
** NOTE: First need to convert these nominal amounts to real amounts (confusing 
** that you haven't done this in the same place in the files for each EITC measure)
** EITC measures based on legislated maximum benefit amount are already in real
** terms, but the simulated EITC variable is still nominal.  Convert it to real
gen r_taxsim_eic_MidGenMax = taxsim_eic_MidGenMax*real
gen r_Sum_taxsim_eic_MidGenMoms = Sum_taxsim_eic_MidGenMoms*real
gen EITC_sim_v3 = r_Sum_taxsim_eic_MidGenMoms
replace EITC_sim_v3 = r_taxsim_eic_MidGenMax if EITC_sim_v3==. 



gen AgeGroup2 = (age>46 & age<55)
gen AgeGroup3 = (age>54 & age<64)
gen AgeGroup4 = (age>63)

gen Over64 = (age>64)



** Create some interactions that will be useful for heterogeneity analysis
gen Male=(Female==0)
gen Male_EITC_v3 = Male*EITC_v3
gen Married_EITC_v3 = Married*EITC_v3
gen White_EITC_v3 = White*EITC_v3

gen AgeGroup2_EITC_v3 = AgeGroup2*EITC_v3
gen AgeGroup3_EITC_v3 = AgeGroup3*EITC_v3
gen AgeGroup4_EITC_v3 = AgeGroup4*EITC_v3

gen InHealthReg = (ExcellentVeryGoodHealth~=. & EITC_v3~=. & age~=. & AgeSq~=. & Female~=. & Married~=. & White~=. & HSGrad~=. & SomeCollege~=. & CollegeGrad~=. &  unemp_rate~=. & r_MaxWelf~=. & state_rate_wages~=. & minwage~=. & gdp~=. & year~=.)

save CPS/OrganizedOldGenData_CPS, replace

